package com.htd.erp.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * @author Zhang Guilin
 *
 */
@Entity
public class PurchaseTicket extends Ticket {

	private static final long serialVersionUID = -254006104758256221L;
	
	@NotNull
	@ManyToOne
	private Supplier supplier;

	private float prepayments;
	
	@Column(length = 420)
	@Size(max = 140)
	private String deliveryAddress;
	
	@OneToMany(mappedBy="purchaseTicket", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private List<PurchaseItem> purchaseItems;
	
	public Supplier getSupplier() {
		return supplier;
	}

	public void setSupplier(Supplier supplier) {
		this.supplier = supplier;
	}

	public float getPrepayments() {
		return prepayments;
	}

	public void setPrepayments(float prepayments) {
		this.prepayments = prepayments;
	}

	public String getDeliveryAddress() {
		return deliveryAddress;
	}

	public void setDeliveryAddress(String deliveryAddress) {
		this.deliveryAddress = deliveryAddress;
	}

	public List<PurchaseItem> getPurchaseItems() {
		if(purchaseItems == null) {
			purchaseItems = new ArrayList<PurchaseItem>();
		}
		return purchaseItems;
	}

	public void setPurchaseItems(List<PurchaseItem> purchaseItems) {
		this.purchaseItems = purchaseItems;
	}
}
